using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Input.Touch;
using Microsoft.Xna.Framework.Media;
using WindowsPhoneTron;

namespace WindowsPhoneTron.Graphic
{
    static class Arena
    {
        public static Texture2D playerVerticalTrail,
                         playerHorizontalTrail,
                         playerUpLeftTrail,
                         playerUpRightTrail,
                         playerDownLeftTrail,
                         playerDownRightTrail;
        
        public static Texture2D enemyVerticalTrail,
                         enemyHorizontalTrail,
                         enemyUpLeftTrail,
                         enemyUpRightTrail,
                         enemyDownLeftTrail,
                         enemyDownRightTrail;

        public static Texture2D wall;

        public static void Draw(SpriteBatch batch)
        {
            Logic.Tile[,] map = Logic.Arena.Instance.Map;

            for (int x = 0; x < 29; x++)
            {
                for (int y = 0; y < 29; y++)
                {
                    Vector2 position = new Vector2((float)((x + 12) * 16) + Tron.MARGIN_X, (float)28 * 16 - (y * 16) + Tron.MARGIN_Y);
                    if (map[x, y].type == Logic.Tile.Type.WALL)
                    {
                        batch.Draw(wall, position, null, Color.White, 0.0f, new Vector2(8.0f, 8.0f), 1.0f, SpriteEffects.None, 0.0f);
                    }
                    else if (map[x, y].type == Logic.Tile.Type.VERTICAL)
                    {
                        if (map[x, y].owner == Logic.Tile.Owner.PLAYER)
                            batch.Draw(playerVerticalTrail, position, null, Color.White, 0.0f, new Vector2(8.0f, 8.0f), 1.0f, SpriteEffects.None, 0.0f);
                        else if (map[x, y].owner == Logic.Tile.Owner.ENEMY)
                            batch.Draw(enemyVerticalTrail, position, null, Color.White, 0.0f, new Vector2(8.0f, 8.0f), 1.0f, SpriteEffects.None, 0.0f);
                    }
                    else if (map[x, y].type == Logic.Tile.Type.HORIZONTAL)
                    {
                        if (map[x, y].owner == Logic.Tile.Owner.PLAYER)
                            batch.Draw(playerHorizontalTrail, position, null, Color.White, 0.0f, new Vector2(8.0f, 8.0f), 1.0f, SpriteEffects.None, 0.0f);
                        else if (map[x, y].owner == Logic.Tile.Owner.ENEMY)
                            batch.Draw(enemyHorizontalTrail, position, null, Color.White, 0.0f, new Vector2(8.0f, 8.0f), 1.0f, SpriteEffects.None, 0.0f);
                    }
                    else if (map[x, y].type == Logic.Tile.Type.UP_LEFT)
                    {
                        if (map[x, y].owner == Logic.Tile.Owner.PLAYER)
                            batch.Draw(playerUpLeftTrail, position, null, Color.White, 0.0f, new Vector2(8.0f, 8.0f), 1.0f, SpriteEffects.None, 0.0f);
                        else if (map[x, y].owner == Logic.Tile.Owner.ENEMY)
                            batch.Draw(enemyUpLeftTrail, position, null, Color.White, 0.0f, new Vector2(8.0f, 8.0f), 1.0f, SpriteEffects.None, 0.0f);
                    }
                    else if (map[x, y].type == Logic.Tile.Type.UP_RIGHT)
                    {
                        if (map[x, y].owner == Logic.Tile.Owner.PLAYER)
                            batch.Draw(playerUpRightTrail, position, null, Color.White, 0.0f, new Vector2(8.0f, 8.0f), 1.0f, SpriteEffects.None, 0.0f);
                        else if (map[x, y].owner == Logic.Tile.Owner.ENEMY)
                            batch.Draw(enemyUpRightTrail, position, null, Color.White, 0.0f, new Vector2(8.0f, 8.0f), 1.0f, SpriteEffects.None, 0.0f);
                    }
                    else if (map[x, y].type == Logic.Tile.Type.DOWN_LEFT)
                    {
                        if (map[x, y].owner == Logic.Tile.Owner.PLAYER)
                            batch.Draw(playerDownLeftTrail, position, null, Color.White, 0.0f, new Vector2(8.0f, 8.0f), 1.0f, SpriteEffects.None, 0.0f);
                        else if (map[x, y].owner == Logic.Tile.Owner.ENEMY)
                            batch.Draw(enemyDownLeftTrail, position, null, Color.White, 0.0f, new Vector2(8.0f, 8.0f), 1.0f, SpriteEffects.None, 0.0f);
                    }
                    else if (map[x, y].type == Logic.Tile.Type.DOWN_RIGHT)
                    {
                        if (map[x, y].owner == Logic.Tile.Owner.PLAYER)
                            batch.Draw(playerDownRightTrail, position, null, Color.White, 0.0f, new Vector2(8.0f, 8.0f), 1.0f, SpriteEffects.None, 0.0f);
                        else if (map[x, y].owner == Logic.Tile.Owner.ENEMY)
                            batch.Draw(enemyDownRightTrail, position, null, Color.White, 0.0f, new Vector2(8.0f, 8.0f), 1.0f, SpriteEffects.None, 0.0f);
                    }
                }
            }
        }
    }
}
